var myiscroll;
var name="";
var employeeId ="";
var reportDate="";
$(document).ready(function(){
	$(window).resize(function(){//当窗口大小改变时自动重新计算
		iscroll();
		myiscroll.refresh();
	});
	// 初始化页面所有参数
	/*
	var aUrl = location.href;
	var urlInfo = (aUrl.substr(aUrl.indexOf("?")+1)).split("&");
	var employeeId = urlInfo[0].split("=")[1];
	var reportDate = urlInfo[1].split("=")[1];
	var mm = reportDate.substr(5);
	name = urlInfo[2].split("=")[1];
	name = decodeURI(name,"utf-8");
	*/
	employeeId = getQueryParam("emplid");
	reportDate = getQueryParam("report_date");
	name = decodeURI(getQueryParam("name"),"utf-8");
	var mm = reportDate.substr(5);
	$("#reprotTitle").text(name+"的"+mm+"月汇报");// 设置报表的汇报人姓名和汇报月份
	$("#loadingText").show();
	$("#ContentIscrollHeight").hide();
	$("#FooterFixed").hide();
	//查询页面信息
	initContent(employeeId,reportDate,false);
	// 返回上页
	$("#back").on("tap",function returnBack(){
		var aUrl = location.href;
		var urlInfo = aUrl.substr(aUrl.indexOf("?"));
		//location.href="/mobile/underlingReport/xslb-chakan2.html" + urlInfo;
		var param = "emplid="+employeeId+"&report_date="+reportDate+"&name="+name;
		gotoLocation("/mobile/underlingReport/xslb-chakan2.html",param);
	});
});
// 初始化页面方法employeeId为下属ID,reportDate为报告日期,flag是否时更换日期调用
function initContent(employeeId,reportDate,flag){
	$.ajax({
		type: "post",
		url: mpsurl+"/mobile/report/queryUnderlingReportGrade.do",
		dataType: "json",
		data: {method:"underlingGrade2",underlingEmplid:employeeId,report_date:reportDate},
		success: function(data){
			$("#loadingText").hide();
			$("#ContentIscrollHeight").show();
			var reportData = eval(data);
			if(reportData.resultCode == "500600"){
				$("#FooterFixed").show();
				var reportInfo = reportData.value;// 所有报表内容
				var report = reportInfo.report;// 主要信息
				var gradeInfo = reportInfo.reportGrade;// 关键信息评分概要显示列表
				var ewg = reportInfo.ewg;
				if(ewg.length==0||reportInfo.iscyc =="0"){//如果没有关键工作计划或者是非评分月则将其隐藏
						$("#gjxx").hide();
				}else{
					for(var i = 0;i < ewg.length;i ++){
						var descr = ewg[i].ewg_descr;
						var weight = ((ewg[i].ewg_weight)+ "").indexOf(".") != -1 ? new Number((ewg[i].ewg_weight)).toFixed(1) + "%" : new Number((ewg[i].ewg_weight)).toFixed(0) + "%";
						var selfRating = ewg[i].ewg_self_rating;
						var othRating = ewg[i].ewg_oth_rating;
						var perDetail = "<li><div class='score-table-td'><div class='row-left-icon'><i>"+(i+1)+"</i></div>"+
				            "<div class='info-list-cont'>"+descr+"</div></div><div class='score-table-td'>"+weight+"</div>"+
				            "<div class='score-table-td'>"+selfRating+"</div>"+
				            "<div class='score-table-td'>"+othRating+"<div></li>";
						$("#workPlanDetail").append(perDetail);
					}
				}
				var selfTotleGrade = gradeInfo.self_grade100;
				var otherTotleGrade = gradeInfo.assess1_grade100;
				if(selfTotleGrade==""||selfTotleGrade==" "){
					selfTotleGrade = 0.0;
				}else{
					selfTotleGrade = parseFloat(selfTotleGrade).toFixed(1);
				}
				if(otherTotleGrade==""||otherTotleGrade==" "){
					otherTotleGrade = 0.0;
				}else{
					otherTotleGrade = parseFloat(otherTotleGrade).toFixed(1);
				}
				// 添加总评分栏
				var totalContent = "<li><div class='score-table-td'></div><div class='score-table-td'>总评分</div>"+
			        "<div class='score-table-td'>"+selfTotleGrade+"</div><div class='score-table-td'>"+otherTotleGrade+"</div></li>";
				$("#workPlanDetail").append(totalContent);
				$("#selfGrade").text(gradeInfo.self_grade5);// 添加自评分
				// 评审人ID 
				var report = reportInfo.report;
				var report_status = report.report_status;
				var EP_MANAGER1_ID = report.eP_MANAGER1_ID;
				var EP_MANAGER2_ID = report.eP_MANAGER2_ID;
				var EP_MANAGER3_ID = report.eP_MANAGER3_ID;
				// 详细信息
				var assess1 = gradeInfo.assess1.replace(/\n/g,"<br>");
				var assess1Name = report.manager1_name;
				var grade15 = gradeInfo.assess1_grade5;
				var assess2 = gradeInfo.assess2.replace(/\n/g,"<br>");
				var assess2Name = report.manager2_name;
				var grade25 = gradeInfo.assess2_grade5;
				var assess3 = gradeInfo.assess3.replace(/\n/g,"<br>");
				var assess3Name = report.manager3_name;
				var grade35 = gradeInfo.assess3_grade5;
				var gradeArray = new Array();
				// 设置已保存的意见;设置标尺,数值,对应评语信息;封装显示评语信息
				var i=0;
				if(report_status == "APP"){
					gradeArray[i] = {"assessName":assess1Name,"grade5":grade15,"assess":assess1};
					i++;
				}	
				if(report.ep_manager2_status == "Y"){
					gradeArray[i] = {"assessName":assess2Name,"grade5":grade25,"assess":assess2};
					i++;
				}
				if(report.ep_manager3_status == "Y"){
					gradeArray[i] = {"assessName":assess3Name,"grade5":grade35,"assess":assess3};
				}
				var gradeLen = gradeArray.length; 
				if(gradeLen > 0){
					for(var k = 0;k < gradeLen;k ++){
						for(var pos in gradeArray[k]){
							if(pos == "assessName"){
								var detailMsg = "<div class='row-info row-info-readonly single-row m-b18'>" +
										"<ul class='row-info-list'><li><div class='info-list-cont'><span class='fn-c-3580d5'>"+
										gradeArray[k]['assessName']+"</span><span class='fn-c-999'>评分：</span><span class='fn-c-3580d5'>" +
										gradeArray[k]['grade5']+"</span><span class='fn-c-999'>分</span></div></li><li><div class='info-list-cont'>" +
										"<p style=\"word-break: break-all;\"><span class='fn-c-999'>意见：</span><span>"+gradeArray[k]['assess']+"</span></p></div></li></ul></div>";
								$("#gradeDetail").append(detailMsg);
							}
						}
					}
				}
				// 页面滑动
				var wh = window.innerHeight-90-112; 
				$("#content").css("height",wh+"px");
				myiscroll = new iScroll("content");
			}else{
				$("#content").hide();
				var tourl="/mobile/underlingReport/xslb-pingfen2.html?underlingEmplid="
						+employeeId+"&report_date="+reportDate+"&name="+name;
				checkLogin(reportData.resultCode,tourl,reportData.resultMessage);
			}	
		},
		error: function(XMLHttpRequest,textStatus,errorThrown){
			$("#loadingText").hide();
			$("#content").hide();
			errorMask("网络连接异常");
		}
	});
}


